package com.mall.order.service.impl;

import com.mall.order.model.OrderSku;
import com.mall.order.mapper.OrderSkuMapper;
import com.mall.order.service.IOrderSkuService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.List;

/**
 * <p>
 * 订单明细表 服务实现类
 * </p>
 *
 * @author Darren
 * @since 2022-08-29
 */
@Service
public class OrderSkuServiceImpl extends ServiceImpl<OrderSkuMapper, OrderSku> implements IOrderSkuService {
    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean addOrderSku(OrderSku ordersku){
        return super.save(ordersku);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean deleteById(String id){
        return super.removeById(id);
    }

    @Override
    @Transactional(rollbackFor = {Exception.class})
    public boolean updateOrderSku(OrderSku ordersku){
        return super.updateById(ordersku);
    }

    @Override
    public OrderSku getById(String id){
        return super.getById(id);
    }

    @Override
    public List<OrderSku> selectList(OrderSku ordersku){
        return super.list(getQueryWrapper(ordersku));
    }

    @Override
    public Page<OrderSku> selectPage(Page<OrderSku> page, OrderSku ordersku){
        return super.page(page, getQueryWrapper(ordersku));
    }

    public LambdaQueryWrapper<OrderSku> getQueryWrapper(OrderSku ordersku){
        return Wrappers.<OrderSku>lambdaQuery()
            .eq(ObjectUtils.isNotEmpty(ordersku.getId()), OrderSku::getId, ordersku.getId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getCategoryOneId()), OrderSku::getCategoryOneId, ordersku.getCategoryOneId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getCategoryTwoId()), OrderSku::getCategoryTwoId, ordersku.getCategoryTwoId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getCategoryThreeId()), OrderSku::getCategoryThreeId, ordersku.getCategoryThreeId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getSpuId()), OrderSku::getSpuId, ordersku.getSpuId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getSkuId()), OrderSku::getSkuId, ordersku.getSkuId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getOrderId()), OrderSku::getOrderId, ordersku.getOrderId())
            .eq(ObjectUtils.isNotEmpty(ordersku.getName()), OrderSku::getName, ordersku.getName())
            .eq(ObjectUtils.isNotEmpty(ordersku.getPrice()), OrderSku::getPrice, ordersku.getPrice())
            .eq(ObjectUtils.isNotEmpty(ordersku.getNum()), OrderSku::getNum, ordersku.getNum())
            .eq(ObjectUtils.isNotEmpty(ordersku.getMoney()), OrderSku::getMoney, ordersku.getMoney())
            .eq(ObjectUtils.isNotEmpty(ordersku.getImage()), OrderSku::getImage, ordersku.getImage())
        ;
    }
}
